package com.ruoyi.ly.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ly.domain.vo.AllProjectVO;
import com.ruoyi.ly.service.ProjectService;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ly.domain.ServeExamineConfig;
import com.ruoyi.ly.service.IServeExamineConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检配置Controller
 * 
 * @author wj
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/ctnm-ly/config")
@Slf4j
public class ServeExamineConfigController extends BaseController
{
    @Autowired
    private IServeExamineConfigService serveExamineConfigService;

    @Autowired
    private ProjectService projectService;

    /**
     * 查询巡检配置列表
     */
    @PreAuthorize("@ss.hasPermi('ctnm-ly:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServeExamineConfig serveExamineConfig)
    {
        startPage();
        List<ServeExamineConfig> list = serveExamineConfigService.selectServeExamineConfigList(serveExamineConfig);
        return getDataTable(list);
    }

    /**
     * 导出巡检配置列表
     */
    @PreAuthorize("@ss.hasPermi('ctnm-ly:config:export')")
    @Log(title = "巡检配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServeExamineConfig serveExamineConfig)
    {
        List<ServeExamineConfig> list = serveExamineConfigService.selectServeExamineConfigList(serveExamineConfig);
        ExcelUtil<ServeExamineConfig> util = new ExcelUtil<ServeExamineConfig>(ServeExamineConfig.class);
        util.exportExcel(response, list, "巡检配置数据");
    }

    /**
     * 获取巡检配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('ctnm-ly:config:query')")
    @GetMapping(value = "/{examineConfigId}")
    public AjaxResult getInfo(@PathVariable("examineConfigId") Long examineConfigId)
    {
        return success(serveExamineConfigService.selectServeExamineConfigByExamineConfigId(examineConfigId));
    }

    /**
     * 新增巡检配置
     */
    @PreAuthorize("@ss.hasPermi('ctnm-ly:config:add')")
    @Log(title = "巡检配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServeExamineConfig serveExamineConfig)
    {
        return toAjax(serveExamineConfigService.insertServeExamineConfig(serveExamineConfig));
    }

    /**
     * 修改巡检配置
     */
    @PreAuthorize("@ss.hasPermi('ctnm-ly:config:edit')")
    @Log(title = "巡检配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServeExamineConfig serveExamineConfig)
    {
        return toAjax(serveExamineConfigService.updateServeExamineConfig(serveExamineConfig));
    }

    /**
     * 删除巡检配置
     */
    @PreAuthorize("@ss.hasPermi('ctnm-ly:config:remove')")
    @Log(title = "巡检配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examineConfigIds}")
    public AjaxResult remove(@PathVariable Long[] examineConfigIds)
    {
        return toAjax(serveExamineConfigService.deleteServeExamineConfigByExamineConfigIds(examineConfigIds));
    }


    //查询所有项目和企业
    @ApiOperation("查询所有项目和企业")
    @GetMapping("/selectAll")
    public Result< List<AllProjectVO>> selectAll() {
        log.info("查询所有项目和企业：{}");
        List<AllProjectVO> allProjectVOList= projectService.selectAll();
        return Result.success(allProjectVOList);
    }

}
